Assignemnt #66 and 64th program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 64th Program
///File name: Sixt4Prog.java
///Date Finished:11/17/2015
import java.util.Scanner;
import java.util.Random;
public class Sixt4Prog
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int x, number, tries=0;
System.out.println( "I'm thinking of a number between 1-100. You have seven guesses." );
System.out.print( "> " );
number = keyboard.nextInt();
System.out.println( "" );
x = 1 + r.nextInt(100);
while (number != x && tries < 6 )
{
System.out.println("\nIncorrect, try again.");
System.out.print( "> " );
number = keyboard.nextInt();
tries++;
}
if ( number == x )
{
System.out.println( "You got it. great job!" );
}
else if ( tries >= 6 )
{
System.out.println( "\nYou're out of attempts. Sorry" );
}
}
}
Picture of the output